package com.example.experiment4sqlite

import android.content.Intent
import android.database.sqlite.SQLiteDatabase
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.view.View
import com.example.experiment4sqlite.utils.UserDbHelper

const val TAG = "DEBUG"

class MainActivity : AppCompatActivity() {
    lateinit var user: UserDbHelper
    lateinit var db: SQLiteDatabase

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)

        user = UserDbHelper(this)
        // Gets the data repository in read mode
        db = user.readableDatabase
    }

    fun onClick(view: View) {
        when (view.id) {
            R.id.search_delete_button -> {
                val intent1 = Intent(this, FindAndDelUserActivity::class.java)
                startActivity(intent1)
            }
            R.id.update_button -> {
                val intent2 = Intent(this, UpdateUserActivity::class.java)
                startActivity(intent2)
            }
            R.id.add_button -> {
                val intent3 = Intent(this, InsertUserActivity::class.java)
                startActivity(intent3)
            }
        }
    }

    override fun onDestroy() {
        user.close()
        super.onDestroy()
    }
}
